//
//  OilRechargeController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/11.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "OilRechargeController.h"

#import "OilChooseView.h"
#import "OilPayView.h"

@interface OilRechargeController ()<OilChooseViewDelegate>

@property(nonatomic,strong)XRCarouselView *XrCarouselView;

@property (nonatomic,strong)UITextField *phoneNumText;

@property (nonatomic,strong)UITextField *nameText;

@property(nonatomic,strong)UIView *OilInfoView;

@end

@implementation OilRechargeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = BACKGROUND_COLOR;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self addViews];
}

- (void)addViews
{
    
    [self.view addSubview:self.XrCarouselView];
    
    //适配
    CGFloat margin= 5;
    CGFloat inputCount;
    CGFloat chooseCount;
    CGFloat height;
    if (iPhone5) {
        inputCount = 10;
        chooseCount = 7;
        height = 25;
    }else if (iPhone6) {
        inputCount = 9;
        chooseCount = 6;
        height = 30;
    } else {
        inputCount = 9;
        chooseCount = 6;
        height = 35;
    }
    
    [self addOilInfoView:margin height:height];
    
    OilChooseView *chooseView = [[OilChooseView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.OilInfoView.frame)+margin, WIDTH, HEIGHT/chooseCount)];
    [self.view addSubview:chooseView];
    chooseView.delegate = self;
    
    
    OilPayView *payView = [[OilPayView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(chooseView.frame), WIDTH,HEIGHT-self.XrCarouselView.Height-chooseView.Height-self.OilInfoView.Height-margin*2)];
    [self.view addSubview:payView];
}

#pragma mark >>>>>>>>>>OilChooseView代理
- (void)OilChooseViewDidClick:(UIButton *)button
{
    
    [self resignResponderTextField];
    
    if (button.tag == 1000) {
        NSLog(@"0");
    }else {
        NSLog(@"1");
    }
}

- (UIView *)addOilInfoView:(CGFloat)margin height:(CGFloat)height
{
    UIView *OilInfoView = [[UIView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.XrCarouselView.frame) + margin, WIDTH, HEIGHT/5.5)];
    self.OilInfoView = OilInfoView;
    [self.view addSubview:OilInfoView];
    OilInfoView.backgroundColor = [UIColor whiteColor];
    
    UILabel *oilLabel = [[UILabel alloc] initWithFrame:CGRectMake(15,10,WIDTH-30,10)];
    [OilInfoView addSubview:oilLabel];
    oilLabel.text = @"加油卡号 : 10102013123";
    oilLabel.font = [UIFont systemFontOfSize:15];
    oilLabel.textColor = [UIColor grayColor];
    
    UITextField * phoneNumText= [[UITextField alloc] initWithFrame:CGRectMake(15,CGRectGetMaxY(oilLabel.frame)+15,oilLabel.width,height)];
    phoneNumText.placeholder = @"请输入手机号码";
    [OilInfoView addSubview:phoneNumText];
    phoneNumText.borderStyle = UITextBorderStyleRoundedRect;
    phoneNumText.font = [UIFont systemFontOfSize:14];
    phoneNumText.textColor = [UIColor blackColor];
    phoneNumText.keyboardType = UIKeyboardTypeNumberPad;
    self.phoneNumText = phoneNumText;
    
    UITextField * nameText= [[UITextField alloc] initWithFrame:CGRectMake(15,CGRectGetMaxY(phoneNumText.frame)+15,oilLabel.width,height)];
    nameText.placeholder = @"持卡人姓名";
    [OilInfoView addSubview:nameText];
    nameText.borderStyle = UITextBorderStyleRoundedRect;
    nameText.font = [UIFont systemFontOfSize:14];
    nameText.textColor = [UIColor blackColor];
    self.nameText = nameText;
    
    return OilInfoView;
}

#pragma mark>>>>>>>>>>懒加载轮播
- (XRCarouselView *)XrCarouselView
{
    if (!_XrCarouselView) {
        NSArray *imageArr = @[
                              [UIImage imageNamed:@"vn2.jpg"],
                              [UIImage imageNamed:@"vn3.jpg"],
                              [UIImage imageNamed:@"vn1.jpg"]
                              ];
        _XrCarouselView = [XRCarouselView carouselViewWithFrame:CGRectMake(0,0, WIDTH, HEIGHT/6) imageArray:imageArr];
        _XrCarouselView.time = 2;
    }
    return _XrCarouselView;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self resignResponderTextField];
}

- (void)resignResponderTextField {
    [self.phoneNumText resignFirstResponder];
    [self.nameText resignFirstResponder];
}

@end
